package com.hnqcgczy.controller;

import com.hnqcgczy.service.IProductService;
import com.hnqcgczy.service.impl.ProductServiceImpl;
import com.hnqcgczy.vo.TProduct;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/search")
public class SearchServlet extends HttpServlet {
    //实现商品模糊搜索
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String proName=req.getParameter("proName");
        System.out.println(proName);
       //获取服务层接口数据
        IProductService ps=new ProductServiceImpl();
        List<TProduct> searchList=ps.getProductList(proName,8);
        //将数据存储于request作用域
        req.setAttribute("searchList",searchList);
        //跳转到商品搜索列表页
        //数据存储于request,所以只能用转发，不能重定向
        req.getRequestDispatcher("/search.jsp").forward(req,resp);
    }
}
